package com.crland.service.oc.impl;

import com.crland.entity.oc.OcMemberInfo;
import com.crland.mapper.oc.OcMemberInfoMapper;
import com.crland.service.oc.OcMemberInfoService;
import com.crland.utils.DataSourceContextHolder;
import com.github.pagehelper.PageHelper;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.ArrayList;
import java.util.List;

public class OcMemberServiceImpl implements OcMemberInfoService {
    @Override
    public List<OcMemberInfo> selectAll(int offset,int limit){
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        DataSourceContextHolder.setDbType("ocDataSource");
        OcMemberInfoMapper ocMemberInfoMapper = ctx.getBean(OcMemberInfoMapper.class);
        List<OcMemberInfo> ocMemberInfoList = new ArrayList<OcMemberInfo>();
        PageHelper.offsetPage(offset,limit);
        ocMemberInfoList = ocMemberInfoMapper.selectAll();
        return ocMemberInfoList;
    }

    @Override
    public String count() {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        DataSourceContextHolder.setDbType("ocDataSource");
        OcMemberInfoMapper ocMemberInfoMapper = ctx.getBean(OcMemberInfoMapper.class);
        String count = ocMemberInfoMapper.count();
        return count;
    }
}
